#include <iostream>
#include "../logs/delegate.h"
#include <unistd.h>

#define de(str) std::cout << str << std::endl;

void loggertest(const std::string &_logger_name)
{
    logger::Logger::ptr lp = logger::getlogger(_logger_name);
    de("-------------------------------------------------");
    assert(lp.get());
    //de("-------------------------------------------------");
    //LOGF("------------example--------------------");
    // lp->debug("%s", "logger->debug");
    // lp->info("%s", "logger->info");
    // lp->warn("%s", "logger->warn");
    // lp->error("%s", "logger->error");
    // lp->fatal("%s", "logger->fatal");
    // LOG_DEBUG(lp, "%s", "LOG_DEBUG");
    // LOG_INFO(lp, "%s", "LOG_INFO");
    // LOG_WARN(lp, "%s", "LOG_WARN");
    // LOG_ERROR(lp, "%s", "LOG_ERROR");
    // LOG_FATAL(lp, "%s", "LOG_FATAL");
    // LOGF("---------------------------------------");

    std::string log_msg = "hello bitejiuyeke-";
    size_t fsize = 0;
    size_t count = 0;
    while (count < 1000)
    {
        usleep(10000);
        std::string msg = log_msg + std::to_string(count++);
        lp->error("%s", msg.c_str());
    }
}

void function_test()
{
    logger::GlobalLoggerBuilder::ptr sgl(new logger::GlobalLoggerBuilder());
    sgl->buildLoggerName("_delegate_test");
    sgl->buildLoggerLevel(logger::LogLevel::value::DEBUG);
    //logger::Formatter::ptr fm(new logger::Formatter("[%d][%c][%f:%l][%p] %m%n"));
    sgl->buildFormatter("[%d][%c][%f:%l][%p] %m%n");
    sgl->buildSink<logger::StdoutSink>();
    sgl->buildSink<logger::FileSink>("./logs/sync.log");
    sgl->buildSink<logger::RollSink>("./logs/roll-", 10 * 1024 ); // args
    sgl->buildLoggerType(logger::Logger::Type::LOGGER_ASYNC);
    sgl->build();
    loggertest("_delegate_test");
}
int main()
{
    function_test();
    //LOGF("------------example--------------------");
    return 0;
}